import Vue from 'vue'
import Vuex from 'vuex'
import * as storage from '@/common/storage'

Vue.use(Vuex)

let storeConf = storage.get('storeConf', false)

const store = new Vuex.Store({
  state: {
    storeConf: storeConf ? JSON.parse(storeConf) : storeConf, // 店铺配置信息
    keywords: '',
    cartNum: 0,
    integralCartNum: 0
  },
  mutations: {
    storeConf(state, data) {
      state.storeConf = data
      storage.set('storeConf', JSON.stringify(data))
    },
    setkeywords(state, data) {
      state.keywords = data
    },
    SET_CARTNUM (state, data) {
      state.cartNum = data
    },
    SET_INTEGRALCARTNUM (state, data) {
      state.integralCartNum = data
    }
  },
  getters: {
    storeConf: state => state.storeConf,
    keywords: state => state.keywords,
    cartNum: state => state.cartNum,
    integralCartNum: state => state.integralCartNum,
  }
})

export default store
